load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_benchmark", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob(["*.h"]) + glob(["*.cpp"]),
)

# Headers designed to be used without source code. Split these out
# into targets if they're meant to be used with source code.
filegroup(
    name = "headers",
    srcs = [
        "admission_context.h",
        "lock_free_read_list.h",
        "spin_lock.h",
        "ticketholder.h",
        "tsan_ignore.h",
    ],
)

mongo_cc_library(
    name = "spin_lock",
    srcs = [
        "spin_lock.cpp",
    ],
    deps = [
        "//src/mongo:base",
    ],
)

mongo_cc_library(
    name = "admission_context",
    srcs = [
        "admission_context.cpp",
    ],
    deps = [
        ":spin_lock",
        "//src/mongo:base",
    ],
)

idl_generator(
    name = "ticketholder_parameters_gen",
    src = "ticketholder_parameters.idl",
)

mongo_cc_library(
    name = "ticketholder",
    srcs = [
        "ticketholder.cpp",
        "ticketholder_parameters_gen",
    ],
    deps = [
        ":admission_context",
        "//src/mongo/db:server_base",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/db/admission/execution_control:execution_control_stats",
        "//src/third_party/boost:boost_filesystem",
        "//src/third_party/boost:boost_iostreams",
        "//src/third_party/boost:boost_log",
        "//src/third_party/boost:boost_program_options",
    ],
)

mongo_cc_library(
    name = "ticketholder_queue_stats",
    srcs = [
        "ticketholder_queue_stats.cpp",
    ],
    deps = [
        ":admission_context",
        "//src/mongo/db:server_base",
        "//src/mongo/db/admission:ingress_admission_control",
        "//src/mongo/db/admission/execution_control:execution_admission_context",
    ],
)

mongo_cc_library(
    name = "thread_pool",
    srcs = [
        "thread_pool.cpp",
    ],
    deps = [
        "//src/mongo:base",
    ],
)

mongo_cc_unit_test(
    name = "util_concurrency_test",
    srcs = [
        "spin_lock_test.cpp",
        "thread_pool_test.cpp",
        "with_lock_test.cpp",
    ],
    tags = [
        "mongo_unittest_third_group",
        "server-programmability",
    ],
    deps = [
        ":spin_lock",
        ":thread_pool",
        ":ticketholder",
        "//src/mongo/db:service_context_test_fixture",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/shard_role:service_context_non_d",
        "//src/mongo/unittest",
        "//src/mongo/util:packaged_task",
    ],
)

mongo_cc_unit_test(
    name = "lock_free_read_list_test",
    srcs = ["lock_free_read_list_test.cpp"],
    tags = ["mongo_unittest_second_group"],
    deps = [],
)

mongo_cc_benchmark(
    name = "lock_free_read_list_bm",
    srcs = [
        "lock_free_read_list_bm.cpp",
    ],
    deps = [
        "//src/mongo/util:processinfo",
    ],
)

mongo_cc_benchmark(
    name = "ticketholder_bm",
    srcs = ["ticketholder_bm.cpp"],
    tags = [
        "second_half_bm",
    ],
    deps = [
        ":ticketholder",
        "//src/mongo/db/admission/execution_control:execution_admission_context",
        "//src/mongo/db/shard_role:service_context_non_d",
        "//src/mongo/db/shard_role/lock_manager",
    ],
)

mongo_cc_unit_test(
    name = "ticketholder_test",
    srcs = [
        "ticketholder_test.cpp",
    ],
    tags = ["mongo_unittest_eighth_group"],
    deps = [
        "//src/mongo/db:service_context_test_fixture",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/shard_role:service_context_non_d",
        "//src/mongo/util:packaged_task",
        "//src/mongo/util/concurrency:ticketholder",
    ],
)
